package com.abs.orm.util;

import java.io.Serializable;

public class StringUtil implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3587630740316966602L;

	public static boolean isEmpty(String arg0) {
		return arg0 == null ? true : "".equals(arg0.trim()) ? true : false;
	}

	public static String toFirstUpper(String arg0) {
		if (!isEmpty(arg0)) {
			return (arg0.substring(0, 1).toUpperCase()
					.concat(arg0.substring(1)));
		}
		return arg0;
	}

	public static String toFirstLower(String arg0) {
		if (!isEmpty(arg0)) {
			return (arg0.substring(0, 1).toLowerCase()
					.concat(arg0.substring(1)));
		}
		return arg0;
	}

	public static String toUpper(String arg0, int position) {
		if (!isEmpty(arg0) && position < arg0.length() && position > -1) {
			return (arg0.substring(0, position).concat(toFirstUpper(arg0
					.substring(position))));
		}
		return arg0;
	}

	public static String toLower(String arg0, int position) {
		if (!isEmpty(arg0) && position < arg0.length() && position > -1) {
			return (arg0.substring(0, position).concat(toFirstLower(arg0
					.substring(position))));
		}
		return arg0;
	}

	public static String toClassName(String arg0, char split) {
		if (!isEmpty(arg0)) {
			return (toFirstUpper(toClassName2(arg0, split)).replaceAll(" ", "")
					.replaceAll("-", ""));
		}
		return arg0;
	}

	private static String toClassName2(String arg0, char split) {
		if (arg0.indexOf(String.valueOf(split)) > -1) {
			int position = arg0.indexOf(String.valueOf(split)) + 1;
			return toClassName2(
					(arg0.substring(0, position).concat(
							toFirstUpper(arg0.substring(position))).replaceFirst(
							String.valueOf(split), "")), split);
		}
		return arg0;
	}

	public static String toClassName(String arg0) {
		if (!isEmpty(arg0)) {
			return ((toClassName(arg0, '_')));
		}
		return arg0;
	}

	public static String toAttriName(String arg0, char split) {
		if (!isEmpty(arg0)) {
			return (toFirstLower(toClassName2(arg0, split)).replaceAll(" ", "")
					.replaceAll("-", ""));
		}
		return arg0;
	}

	public static String toAttriName(String arg0) {
		if (!isEmpty(arg0)) {
			return (toAttriName(arg0, '_'));
		}
		return arg0;
	}
}
